/*
 * Description: 在线消息 - 聊天群 控制器
 * Author: wangyifei
 * DateCreated: 2024-06-06 11:25
 */

import { type IResList, messageHttp, type IRes } from '@/utils/request';
import type { MsgFmt } from '../config';

// 查询列表
export interface GroupParam {
	avatar?: string;
	/** 0=公开， 1=私有 */
	groupType?: number;
	readMark?: number;
	remark?: string;
	sortNo?: number;
	title?: string;
	users?: number;
}
export interface GroupRes extends GroupParam {
	id: number;
	latestMsg: string;
	latestMsgFmt: MsgFmt;
	latestMsgTime: Date;
}
export const selectGroupList = (data: GroupParam) =>
	messageHttp.post<IResList<GroupRes>>({
		url: '/chatting-group/list',
		data
	});

// 新增 在线消息 - 聊天群
export interface InsertGroupParam {
	avatar?: string;
	/** 0=公开， 1=私有 */
	groupType?: 0 | 1;
	remark?: string;
	title?: string;
}
export const insertGroupItem = (data: InsertGroupParam) =>
	messageHttp.post<IRes<GroupRes>>({
		url: '/chatting-group/',
		data
	});

// 修改 在线消息 - 聊天群
export const updateGroupItem = (data: GroupRes) =>
	messageHttp.put<IRes<GroupRes>>({
		url: '/chatting-group/',
		data
	});

// 通过id删除 在线消息 - 聊天群
export const deleteGroupItem = (ids: number[]) =>
	messageHttp.delete({
		url: `/chatting-group/${ids.join(',')}`
	});
